package com.ls.blog.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @program: blog
 * @author: lishun
 * @create: 2021-09-19 09:50
 **/
@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Value("${swagger.enable}")
    //从配置文件中拿到enable的值
    private Boolean enable;
    @Bean
    Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .enable(enable)//是否开始swagger2
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ls.blog"))//扫描包下的才能生成对应的model和api接口
                //.paths()//过滤
                .build();
    }
    private ApiInfo apiInfo(){
        Contact contact = new Contact("ls","#","179468682@qq.com");
        return new ApiInfo(
                "Api Documentation"
                , "Api Documentation"
                , "1.0"
                , "urn:tos"
                , contact
                , "Apache 2.0"
                , "http://www.apache.org/licenses/LICENSE-2.0"
                , new ArrayList());
    }
}
